package com.oi.test01.hw.tiMu5;

import java.lang.reflect.Constructor;
import java.util.Scanner;

/**
 * @author bin
 * @date 2025 - 03 -17
 * 使用反射机制来实现用户输入一个年份，判断是闰年还是平年
 **/
public class MainTest05 {
    public static void main(String[] args) throws Exception {
        System.out.println("请输入需要判断的年份");
        Scanner sc = new Scanner(System.in) ;
        int year = sc.nextInt() ;

        Class<?> checkYearClass = CheckYear.class;

        Constructor<?> constructor = checkYearClass.getConstructor(int.class);

        Object obj =  constructor.newInstance(year);


        if(obj instanceof CheckYear) {
            CheckYear checkYear = (CheckYear)obj ;
            Boolean flag =  checkYear.isLeapYear();
            if(flag)
                System.out.println(year + "是闰年");
            else
                System.out.println(year + "是平年");
        }
    }
}
